//
//  FBOrderViewStatus_OrderAppeal.m
//  XTXOneToOne
//
//  Created by Canny on 2018/11/9.
//  Copyright © 2018年 WK. All rights reserved.
//

#import "FBOrderViewStatus_OrderAppeal.h"

@interface FBOrderViewStatus_OrderAppeal ()

@property (nonatomic,strong) UILabel * lab_0;
@property (nonatomic,strong) UILabel * lab_1;
@property (nonatomic,strong) UILabel * lab_2;
@property (nonatomic,strong) UILabel * lab_3;
@property (nonatomic,strong) UILabel * lab_4;
@property (nonatomic,strong) UILabel * lab_5;

@property (nonatomic,strong) UILabel * serviceQQ;

@property (nonatomic,strong) UILabel * unReadOrderLab;


@end
@implementation FBOrderViewStatus_OrderAppeal

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor=[UIColor whiteColor];
        [self createUI];
    }
    return self;
}


-(void)createUI{
    
    UIView * bgView = [[UIView alloc]init];
    [self addSubview:bgView];
    bgView.backgroundColor=RGB(235, 240, 248);
    bgView.layer.shadowOpacity = 0.5;// 阴影透明度
    bgView.layer.shadowColor = [UIColor grayColor].CGColor;// 阴影的颜色
    bgView.layer.cornerRadius=5;
    bgView.clipsToBounds=YES;
    bgView.layer.shadowRadius = 8;// 阴影扩散的范围控制
    //    bgView.layer.shadowOffset = CGSizeMake(1, 1);// 阴影的范围
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(20);
        make.left.equalTo(self.mas_left).offset(15);
        make.right.equalTo(self.mas_right).offset(-15);
        make.height.equalTo(@(250));
    }];
    
    
    [self setLeftText:@"对方" andRtext:@"" andIndex:0 andbg:bgView];
    [self setLeftText:@"订单金额" andRtext:@"" andIndex:1 andbg:bgView];
    [self setLeftText:@"单价" andRtext:@"" andIndex:2 andbg:bgView];
    [self setLeftText:@"数量" andRtext:@"" andIndex:3 andbg:bgView];
    [self setLeftText:@"订单号" andRtext:@"" andIndex:4 andbg:bgView];
    [self setLeftText:@"订单时间" andRtext:@"" andIndex:5 andbg:bgView];
    
    _serviceQQ = [[UILabel alloc]init];
    [self addSubview:_serviceQQ];
    [self setLab:_serviceQQ withColor:RGB(30, 63, 89) andFont:15 andText:@"订单正在处理中，客服QQ:加载中" andTextAlignment:NSTextAlignmentLeft];
    [_serviceQQ mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bgView.mas_bottom).offset(10);
        make.left.equalTo(self.mas_left).offset(15);
        make.width.mas_equalTo(300);
        make.height.mas_equalTo(30);
    }];
    
    UIButton *  btn1 = [[UIButton alloc]init];
    [self addSubview:btn1];
    btn1.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
//    [btn1 addTarget:self action:@selector(GoToChatVC) forControlEvents:UIControlEventTouchUpInside];
    [btn1 setTitle:@"申诉处理中" forState:UIControlStateNormal];
    [btn1 setTitleColor:MC_THEME_COLOR forState:UIControlStateNormal];
    btn1.backgroundColor=RGB(235,240,248);
    [btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bgView.mas_bottom).offset(50);
        make.left.equalTo(self.mas_left).offset(15);
        make.width.mas_equalTo((G_SCREENWIDTH-30)*0.4);
        make.height.mas_equalTo(40);
    }];
    
    UIButton *  btn2 = [[UIButton alloc]init];
    [self addSubview:btn2];
    btn2.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [btn2 addTarget:self action:@selector(GoToMyMoneyVC) forControlEvents:UIControlEventTouchUpInside];
    [btn2 setTitle:@"查看资产" forState:UIControlStateNormal];
    [btn2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    btn2.backgroundColor=MC_THEME_COLOR;
    [btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bgView.mas_bottom).offset(50);
        make.left.equalTo(btn1.mas_right).offset(0);
        make.width.mas_equalTo((G_SCREENWIDTH-30)*0.6);
        make.height.mas_equalTo(40);
    }];
    
    
    
    UIButton *  chat = [[UIButton alloc]init];
    [self addSubview:chat];
    chat.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [chat addTarget:self action:@selector(GoToChatVC) forControlEvents:UIControlEventTouchUpInside];
    [chat setImage:[UIImage imageNamed:@"消息icon"] forState:UIControlStateNormal];
    [chat mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(btn2.mas_bottom).offset(20);
        make.centerX.equalTo(self.mas_centerX);
        make.width.mas_equalTo(30);
        make.height.mas_equalTo(30);
    }];

    
    
    UILabel * unReadOrderLab = [[UILabel alloc]init];
    [self addSubview:unReadOrderLab];
    unReadOrderLab.layer.borderColor = [UIColor whiteColor].CGColor;
    unReadOrderLab.layer.borderWidth = 1;
    [self setLab:unReadOrderLab withColor:[UIColor whiteColor] andFont:9 andText:@"" andTextAlignment:NSTextAlignmentCenter];
    unReadOrderLab.layer.cornerRadius = 9;
    unReadOrderLab.clipsToBounds=YES;
    unReadOrderLab.backgroundColor=[UIColor redColor];
    [unReadOrderLab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(btn2.mas_bottom).offset(11);
        make.centerX.equalTo(self.mas_centerX).offset(5);
        make.width.mas_equalTo(18);
        make.height.mas_equalTo(18);
    }];
    _unReadOrderLab=unReadOrderLab;
    _unReadOrderLab.hidden=YES;
}


-(void)setLeftText:(NSString *)text1 andRtext:(NSString *)text2 andIndex:(NSInteger)index  andbg:(UIView * )bg{
    CGFloat Top = index* 40 +5;
    UILabel * left = [[UILabel alloc]init];
    [bg addSubview:left];
    [self setLab:left withColor:RGB(140, 159, 173) andFont:14 andText:text1 andTextAlignment:NSTextAlignmentLeft];
    [left mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bg.mas_top).offset(Top);
        make.left.equalTo(bg.mas_left).offset(15);
        make.right.equalTo(bg.mas_right).offset(-15);
        make.height.equalTo(@(35));
    }];
    
    text2 = [NSString stringWithFormat:@"%@",text2];
    UILabel * right = [[UILabel alloc]init];
    [bg addSubview:right];
    [self setLab:right withColor:RGB(30, 63, 89) andFont:14 andText:text2 andTextAlignment:NSTextAlignmentRight];
    [right mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bg.mas_top).offset(Top);
        make.left.equalTo(bg.mas_left).offset(15);
        make.right.equalTo(bg.mas_right).offset(-15);
        make.height.equalTo(@(35));
    }];
    if (index==0) {
        _lab_0 = right;
    }else if (index==1){
        _lab_1 = right;
    }else if (index==2){
        _lab_2 = right;
    }else if (index==3){
        _lab_3 = right;
    }else if (index==4){
        _lab_4 = right;
    }else if (index==5){
        _lab_5 = right;
    }
    
}

-(void)setLab:(UILabel *)lab withColor:(UIColor *)color andFont:(CGFloat)font andText:(NSString *)text andTextAlignment:(NSTextAlignment)textAlignment{
    lab.text=text;
    lab.textColor=color;
    lab.font=[UIFont systemFontOfSize:font];
    lab.textAlignment=textAlignment;
}


-(void)setDataSource:(FBFindorderModel *)dataSource{
    
    _dataSource = dataSource;
    if (dataSource) {
        _lab_0.text = [NSString stringWithFormat:@"%@",self.dataSource.bill_nickname];
        _lab_1.text = [NSString stringWithFormat:@"%@ %@",self.dataSource.amount,self.dataSource.legal];
        _lab_2.text = [NSString stringWithFormat:@"%@ %@/%@",self.dataSource.price,self.dataSource.legal,self.dataSource.symbol];
        _lab_3.text = [NSString stringWithFormat:@"%@ %@",self.dataSource.volume,self.dataSource.symbol];
        _lab_4.text = [NSString stringWithFormat:@"%@",self.dataSource.order_sn];
        _lab_5.text = [NSString stringWithFormat:@"%@",self.dataSource.create_time];
    }
}

-(void)setSevQQ:(NSString *)sevQQ{

    NSString * str = [NSString stringWithFormat:@"订单正在处理中，客服QQ:%@  ",sevQQ];
    NSRange range = [str rangeOfString:[NSString stringWithFormat:@"%@",sevQQ]];
    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:str];
    // 设置数字为红色
    [attri addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(range.location, range.length)];
    
    _serviceQQ.attributedText=attri;
    
}


#pragma mark-跳转资产
-(void)GoToMyMoneyVC{
    
    if (self.block) {
        self.block(FBFindorderActionType_GoToMoney);
    }
    
}

#pragma mark-跳转消息
-(void)GoToChatVC{
    
    if (self.block) {
        self.block(FBFindorderActionType_GoToChat);
    }
    
}
#pragma mark-设置未读消息数量
-(void)setUnReadOrderNum{
    
    FBFindorderUnReadOrder * FU = [FBFindorderUnReadOrder sharedFBFindorderUnReadOrder];
    NSLog(@"%@",self.dataSource.order_sn);
    NSString * order_sn = [NSString stringWithFormat:@"%@",self.dataSource.order_sn];
    NSString * Num = [NSString stringWithFormat:@"%@",FU.UnReadOrderDic[order_sn]];
    if ([Num integerValue]>0) {
        _unReadOrderLab.text=Num;
        _unReadOrderLab.hidden=NO;
        if ([Num integerValue]<10) {
            _unReadOrderLab.font = [UIFont boldSystemFontOfSize:9];
        }
    }else{
        _unReadOrderLab.hidden=YES;
    }
    
}
@end

